﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FTBS.Models.DAO;
using FTBS.Models.Entities;

namespace FTBS.Models.BLO
{
    public class CategoryBLO
    {
        private CategoryDAO _categoryDao = new CategoryDAO();

        /// <summary>
        /// get list category from DAO
        /// </summary>
        /// <returns></returns>
        /// <author>hungph</author>
        public List<Category> LoadCategories()
        {
            var listCate = _categoryDao.LoadCategories();
            return listCate;
        }

        /// <summary>
        /// get category by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <author>hungph</author>
        public Category LoadCategoryById(int id)
        {
            var cate = _categoryDao.LoadCategoryById(id);
            return cate;
        }

        /// <summary>
        /// create new category
        /// </summary>
        /// <param name="category"></param>
        /// <returns>success: true ,fail : false</returns>
        /// <author>hungph</author>
        public bool CreateCategory(Category category)
        {
            var isSuccess = _categoryDao.Add(category);
            if (isSuccess == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        /// <summary>
        /// edit category
        /// </summary>
        /// <param name="category"></param>
        /// <returns>success: true ,fail : false</returns>
        /// <author>hungph</author>
        public bool EditCategory(Category category)
        {
            var isSuccess = _categoryDao.Edit(category);
            if (isSuccess == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        /// <summary>
        /// delete category
        /// </summary>
        /// <param name="category"></param>
        /// <returns>success: true ,fail : false</returns>
        /// <author>hungph</author>
        public bool DeleteCategory(Category category)
        {
            var isSuccess = _categoryDao.Delete(category);
            if (isSuccess == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        /// <summary>
        /// Check if category name is existed or not
        /// </summary>
        /// <param name="category"></param>
        /// <returns>true : existed; false: not existed</returns>
        /// <author>hungph</author>
        /// <date>3/3/2014</date>
        public bool CheckIsExisted(Category category)
        {
            return (_categoryDao.CheckIsExisted(category));
        }

        public Category GetCategoryById(int id)
        {
            var cate = _categoryDao.GetCategoryById(id);
            return cate;
        }

        /// <summary>
        /// Load Category By username
        /// </summary>
        /// <returns>Film</returns>
        /// <author>DuyHDV</author>
        public int LoadCateByUser(string un)
        {
            int cates = _categoryDao.GetCategoryByUsername(un);
            return cates;
        }

        /// <summary>
        /// check deleteable category
        /// </summary>
        /// <param name="cateId"></param>
        /// <returns>true : can delete category; false: can't delete category</returns>
        public bool CheckDeleteAbleCategory(int cateId)
        {
            var result = _categoryDao.GetNumbersOfFilmByCategory(cateId);
            if (result > 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}